package be.kuleuven.cs.mume.objects;

import java.util.ArrayList;

import org.mt4j.components.TransformSpace;
import org.mt4j.components.visibleComponents.font.FontManager;
import org.mt4j.components.visibleComponents.font.IFont;
import org.mt4j.components.visibleComponents.shapes.AbstractShape;
import org.mt4j.components.visibleComponents.shapes.MTLine;
import org.mt4j.components.visibleComponents.shapes.MTRoundRectangle;
import org.mt4j.components.visibleComponents.widgets.MTTextArea;
import org.mt4j.input.inputProcessors.componentProcessors.lassoProcessor.IdragClusterable;
import org.mt4j.input.inputProcessors.componentProcessors.rotateProcessor.RotateProcessor;
import org.mt4j.input.inputProcessors.componentProcessors.scaleProcessor.ScaleProcessor;
import org.mt4j.util.MTColor;
import org.mt4j.util.animation.Animation;
import org.mt4j.util.animation.MultiPurposeInterpolator;
import org.mt4j.util.math.Ray;
import org.mt4j.util.math.Vector3D;
import org.mt4j.util.math.Vertex;

import processing.core.PApplet;
import processing.core.PGraphics;

public class MediaObject extends AbstractShape implements IdragClusterable {

	String childs[];
	boolean returned;
	String m_id;
	String nodeName;
	public ArrayList<String> conSongs;
	public ArrayList<String> conArtists;
	private boolean expanded = false;

	public enum MediaType {
		ARTIST, SONG, REMIX
	}

	private MediaType type;

	/**
	 * @return the type
	 */
	public MediaType getType() {
		return this.type;
	}

	@Override
	public float getHeightXY(TransformSpace transformSpace) {
		return rect.getHeightXY(transformSpace);
	}

	public void setId(String id) {
		m_id = id;
	}

	public String getId() {
		return m_id;
	}

	public String getNodeName() {
		return nodeName;
	}

	public boolean isExpanded() {
		return this.expanded;
	}

	public boolean expand() {
		if (this.expanded) {
			return true;
		}
		this.expanded = true;
		return false;

	}

	@Override
	public float getWidthXY(TransformSpace transformSpace) {
		return rect.getWidthXY(transformSpace);
	}

	final MTRoundRectangle rect;

	public MediaObject(PApplet applet, float x, float y, String artist,
			MediaType type) {
		super(new Vertex[0], applet);
		this.returned = false;
		this.nodeName = artist;
		this.type = type;
		MTColor clearColor = null;
		switch (type) {
		case ARTIST:
			clearColor = new MTColor(255, 0, 0);
			break;
		case SONG:
			clearColor = new MTColor(0, 255, 0);
			break;
		case REMIX:
			clearColor = new MTColor(0, 0, 255);
			break;
		}
		MTColor white = new MTColor(255, 255, 255);

		IFont fontArial = FontManager.getInstance().createFont(applet,
				"arial.ttf", 25, // Font size
				white, // Font fill color
				white); // Font outline color

		final MTTextArea textField = new MTTextArea(applet, fontArial);

		textField.setNoStroke(true);
		textField.setNoFill(true);
		textField.setPickable(false);
		textField.setText(artist);

		this.rect = new MTRoundRectangle(x, y, 0, textField
				.getWidthXY(TransformSpace.GLOBAL), textField
				.getHeightXY(TransformSpace.GLOBAL), 10, 10, applet);
		this.addChild(this.rect);
		this.rect.addChild(textField);
		this.rect.setFillColor(clearColor);
		this.rect.setPickable(false);
		textField.setPositionGlobal(this.rect.getCenterPointGlobal());

		this.setGestureAllowance(ScaleProcessor.class, false);
		this.setGestureAllowance(RotateProcessor.class, false);

		conSongs = new ArrayList<String>();
		conArtists = new ArrayList<String>();

	}

	public void addArtistConnection(String a) {
		conArtists.add(a);
	}

	public void addSongConnection(String s) {
		conSongs.add(s);
	}

	public void remArtistConnection(String a) {
		conArtists.remove(a);
	}

	public void remSongConnection(String a) {
		conSongs.remove(a);
	}

	@Override
	protected void destroyComponent() {
		// TODO Auto-generated method stub

	}

	@Override
	public Vector3D getCenterPointLocal() {
		return rect.getCenterPointRelativeToParent();
	}

	@Override
	public Vector3D getGeometryIntersectionLocal(Ray ray) {
		return rect.getGeometryIntersectionLocal(ray);
	}

	@Override
	public boolean isGeometryContainsPointLocal(Vector3D testPoint) {
		return rect.isGeometryContainsPointLocal(testPoint);
	}

	@Override
	public void drawComponent(PGraphics g) {
		// TODO Auto-generated method stub

	}

	public String[] getChilds() {
		if (returned)
			return null;
		returned = true;
		return childs;
	}

	public void setChilds(String[] child) {
		childs = child;
	}

	/**
	 * @see org.mt4j.input.inputProcessors.componentProcessors.lassoProcessor.IdragClusterable#isSelected()
	 */
	@Override
	public boolean isSelected() {
		// TODO Auto-generated method stub
		return false;
	}

	/**
	 * @see org.mt4j.input.inputProcessors.componentProcessors.lassoProcessor.IdragClusterable#setSelected(boolean)
	 */
	@Override
	public void setSelected(boolean selected) {
		// TODO Auto-generated method stub
		
	}
}
